/**
 * 
 */
package com.ailk.evaluation.common;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.context.ApplicationContext;

import com.ailk.evaluation.manager.AutoExecutableManager;



/**
 * @author DerekHong
 *
 */
public class JsWriter {
	private ApplicationContext ctx;
	
	/**
	 * @param ctx
	 */
	public JsWriter(ApplicationContext ctx) {
		this.ctx = ctx;
	}

	public void writeAreaJs(String path, String fileName) {	
		StringBuffer sb=new StringBuffer(2000);
		sb.append("var provinceid = new Array;");
		sb.append("var provincename = new Array;");
		sb.append("var cityid = new Array;");
		sb.append("var cityname = new Array;");
		
		AutoExecutableManager manager = (AutoExecutableManager)ctx.getBean("autoExecutable");
		/*OutputResult result = manager.find("provinces", new HashMap<String,Object>(1));
		List<Map> list = result.getList();
		for (int i=0; i<list.size(); i++) {
			sb.append("provinceid["+i+"]="+list.get(i).get("prov_id")+";");
			sb.append("provincename["+i+"]=\""+list.get(i).get("prov_name")+"\";");
		}
		
		result = manager.find("citys", new HashMap<String,Object>(1));
		list = result.getList();
		for (int i=0; i<list.size(); i++) {
			sb.append("cityid["+i+"]=\""+list.get(i).get("prov_id")+"|"+list.get(i).get("city_id")+"\";");
			sb.append("cityname["+i+"]=\""+list.get(i).get("city_name")+"\";");
		}	*/
		FileUtils.saveFileContent(path,fileName,sb.toString(), true);
	}
}
